package com.stud.system.controller.system;

import com.stud.common.annotation.Log;
import com.stud.common.config.StudConfig;
import com.stud.common.core.domain.Result;
import com.stud.common.enums.BusinessType;
import com.stud.common.utils.file.FileUploadUtils;
import com.stud.common.utils.file.MimeTypeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Stud
 * @title 通用文件管理
 * @desription XXXXX
 * @data 2022-08-29 9:36
 */

@Api(tags = "文件管理")
@RestController
@RequestMapping("/system/file")
public class SysFileController {

    @ApiOperation("通用图片上传--返回图片路径")
    @Log(title = "通用图片上传", businessType = BusinessType.UPDATE)
    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestParam("file") MultipartFile file, @RequestParam("businessType") String businessType) throws Exception {
        if (file.isEmpty()) {
            return Result.fail("图片不能为空");
        }
        //校验图片格式.
        String url = FileUploadUtils.upload(StudConfig.getBusinessPath(businessType), file, MimeTypeUtils.IMAGE_EXTENSION);
        return Result.ok("图片上传成功", url);
    }
}
